package com.example.task1.ui.AllService.thehouse;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.TheHouseDetailsBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class TheHouseDetailsActivity extends AppCompatActivity {

    private int id;
    private TextView tvTitle;
    private TextView tvAreaSize;
    private TextView tvPrice;
    private TextView tvPhone;
    private TextView tvAddress;
    private TextView tvHouseType;
    private TextView tvDescription;
    private ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_the_house_details);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("详情");
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        id = getIntent().getIntExtra("id", 0);
        initData();
        initView();
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/house/housing/" + id);
        Api.send(apiRespCall, TheHouseDetailsBean.class, new CallBack<TheHouseDetailsBean>() {
            @Override
            public void success(TheHouseDetailsBean data) {
                TheHouseDetailsBean.DataDTO rows = data.getData();
                MyApplication.glide(image, rows.getPic());
                tvAddress.setText("地址：" + rows.getAddress());
                tvHouseType.setText("房源类型：" + rows.getAddress());
                tvTitle.setText(rows.getSourceName());
                tvPhone.setText("联系方式" + rows.getTel());
                tvPrice.setText("价格：" + rows.getPrice());
                tvDescription.setText("简介" + rows.getDescription());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void initView() {
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvAreaSize = (TextView) findViewById(R.id.tv_areaSize);
        tvPrice = (TextView) findViewById(R.id.tv_price);
        tvPhone = (TextView) findViewById(R.id.tv_phone);
        tvAddress = (TextView) findViewById(R.id.tv_address);
        tvHouseType = (TextView) findViewById(R.id.tv_houseType);
        tvDescription = (TextView) findViewById(R.id.tv_description);
        image = (ImageView) findViewById(R.id.image);
    }
}